package org.batatasframework.support;

import org.springframework.util.Assert;

public abstract class AbstractSupportDefinition implements Comparable<AbstractSupportDefinition>{

	protected final String key;
	protected final String name;
	/** 是否处理定义阶段，如果不是处理定义阶段，则不允许改变这个定义里的值 */
	private boolean definable = true;
	private int ordinal = 100;
	
	@Override
	public int compareTo(AbstractSupportDefinition o) {
		return ordinal - o.ordinal;
	}

	public AbstractSupportDefinition(String key, String name){
		this.key = key;
		this.name = name;
	}
	
	public String getKey() {
		return key;
	}
	
	public String getName() {
		return name;
	}
	
	/** 完成定义，完成后就允许再添加定义的内容了 */
	public void finish(){
		definable = false;
	}
	
	protected void check(){
		Assert.isTrue(definable, "定义已经完成，不允许再进行定义！");
	}

	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		check();
		this.ordinal = ordinal;
	}
}
